<?php
// Check if logged in to the manager and get $uid!=0
if (!($_SESSION['mgrValidated'] && ($uid = $_SESSION['mgrInternalKey']))) {
	return ($debug) ? 'Not manager' : '';
}

$debug_output='';
// Setup $roles
if (isset($role)) {
	if (strpos($role,'|')===false) {
		$roles = array(0 => $role);
	}
	else {
		$roles = explode('|',$role);
	}
}
else { // Not set => only administrators
	$roles = array( 0 => 1);
}
$debug_output .= "roles=".print_r($roles,true)."<br />";

// Snippetname
$snp = isset($snp) ? $snp : '';
$debug_output .= "&snippet=$snp<br />";

// Get userrole
$userinfo = $modx->getUserInfo($uid);
$userrole = $userinfo['role'];
$debug_output .= "userrole=$userrole<br />";

// Check permissions
if (array_search($userrole,$roles)===false) {
	return ($debug) ? $debug_output : '';
}

// Snippetparameters ie &param=`parent:2|tpl:5`
if (isset($param) && strstr($param,':')!== false) {
	$temp = explode('|',$param);
	foreach($temp as $v) {
		list($key,$value) = explode(':',$v);
		$snpparams[$key] = $value;
	}
}
else {
	$snpparams = null;
}

if ($debug)
	$output = $debug_output;
else
	$output = '';

// Run snippet and return result

$output .= $modx->runSnippet($snp,$snpparams);

return $output;
?>